<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ajax
 *
 * @author hassanali
 */
class ajax extends cms_controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('ajax_model');
    }

    public function get_replay_data() {

        $limit = $_POST['limit'];
        $limit = intval($limit);
        $limit = mysql_real_escape_string($limit);

        $order = $_POST['order'];

        $order = mysql_real_escape_string($order);

        $limitstart = $_POST['limitstart'];
        $limitstart = intval($limitstart);
        $limitstart = mysql_real_escape_string($limitstart);

        $id = $_POST['id'];
        $id = intval($id);
        $id = mysql_real_escape_string($id);



        echo json_encode($this->ajax_model->get_message_replay($limit, $limitstart, $id, $order));
    }

    public function get_message_data() {

        $limit = $_POST['limit'];
        $limit = intval($limit);
        $limit = mysql_real_escape_string($limit);

        $order = $_POST['order'];

        $order = mysql_real_escape_string($order);

        $limitstart = $_POST['limitstart'];
        $limitstart = intval($limitstart);
        $limitstart = mysql_real_escape_string($limitstart);

        $id = $_POST['id'];
        $id = intval($id);
        $id = mysql_real_escape_string($id);



        echo json_encode($this->ajax_model->get_message($limit, $limitstart, $id, $order));
    }

    public function sum_cost() {
        $lbs = mysql_real_escape_string($_POST['block_shiping_lbs']);
        $shipment = mysql_real_escape_string($_POST['block_shiping_com']);
        echo $this->inovices->get_shiping_rate($lbs, '', '', $shipment) . ' ريال';
    }

    public function add_malinglist() {
        $this->load->helper('email');
        $email_malinglist = $_POST['email_malinglist'];
        $email_malinglist = mysql_real_escape_string($email_malinglist);
        if (valid_email($email_malinglist)) {
            $sql = $this->db->get_where('mailinglist', array('email' => $email_malinglist));
       
            if ($sql->num_rows()) {
                echo '<div class="ajax_error">' . lang('message_malinglist_error_found') . '</div>';
            } else {
                $this->db->insert('mailinglist',array('email' => $email_malinglist,'create_date'=>date('Y-m-d H:i:s')));
                echo '<div class="ajax_success">' . lang('message_malinglist_success') . '</div>';
            }
        } else {
            echo '<div class="ajax_error">' . lang('message_malinglist_error') . '</div>';
        }
    }

}

?>
